package lambda;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class LambdaUtils {


    public static void main(String[] args) {
        listDuplicateRemoval();
    }



    // 验证distinct的去重作用
    public static void listDuplicateRemoval(){
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("Tony",18));
        personList.add(new Person("Alice",17));
        personList.add(new Person("Tony",19));
        List<String> nameList = personList.stream()
                .map(Person::getName)
                .distinct().collect(Collectors.toList());
        nameList.forEach(p-> System.out.println(p));
    }

    @Data
    @AllArgsConstructor
    public static class Person{
        private String name;
        private Integer age;
    }
}
